// pages/confirm/confirm.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    display: "none",
    _num: 1,
    order_no: '',
  },
  liuyan: function (e) {
    this.setData({
      liuyan: e.detail.value
    })
  },
  show_payment: function () {
    let that = this;
    wx.request({
      url: app.data.Url + 'order/insertOrder',
      data: {
          cart_data:{
            cartid: that.data.cartid,
            order_remark: that.data.liuyan,
          },
        uid: wx.getStorageSync('userInfo').uid
      },
      method: 'post',
      success: function (res) {
        console.log('---------------', res.data.data.order_no)
        that.setData({
          order_no: res.data.data.order_no
        })
      }
    })
    this.setData({
      display: "block"
    })
  },
  hideview: function () {
    let that = this;
    console.log(that.data.order_no, wx.getStorageSync('userInfo').uid)
    wx.request({
      url: app.data.Url + 'order/orderPayParams',
      data: {
        order_no: that.data.order_no,
        title: '智慧社区订单支付',
        uid: wx.getStorageSync('userInfo').uid
      },
      method: 'post',
      success: function (res) {
        wx.requestPayment({
          'timeStamp': res.data.data.weixin.timeStamp,
          'nonceStr': res.data.data.weixin.nonceStr,
          'package': res.data.data.weixin.package,
          'signType': 'MD5',
          'paySign': res.data.data.weixin.paySign,
          'success': function (res) {

          },
          'fail': function (res) {

          }
        })
      }
    })
    this.setData({
      display: "none"
    })
  },
  focus_click: function (e) {
    this.setData({
      _num: e.target.dataset.num
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      money:options.money,
      cartid:options.cartid
    })
    wx.request({
      url: app.data.Url + 'cart/get_detail',
      data: {
        cartid: options.cartid
      },
      method:'post',
      success: function (res) {
        that.setData({
          detail: res.data.data,
          num: options.num,
          money:options.money,
          goodsid: options.goodsid
        })
        console.log(res.data.data)
      }
    })
    wx.request({
      url: app.data.Url + 'address/get_defaultadd',
      data: {
        uid: wx.getStorageSync('userInfo').uid,
      },
      method: 'get',
      success: function (res) {
        that.setData({
          add: res.data.data
        })
        console.log(res.data.data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})